package com.example.springstudy.controller;

import com.example.springstudy.dao.User;
import com.example.springstudy.service.UserService;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Date： 2021/7/22 2:47 下午
 * @Author: annanchen@didiglobal.com
 **/
@Data
@AllArgsConstructor
@RestController
public class UserController {
    private UserService userService;

    @PostMapping("/user")
    public int creat(@RequestBody User user) {
        return userService.create(user.getName(),user.getAge());
    }

    @GetMapping("/user/{name}")
    public List<User> getByName(@PathVariable String name) {
        return userService.getByName(name);
    }

    @DeleteMapping("/user/{name}")
    public int deleteByName(@PathVariable String name) {
        return userService.deleteByName(name);
    }

    @GetMapping("/user/count")
    public int getAllUsers() {
        return userService.getAllUsers();
    }

    @DeleteMapping("/user/all")
    public int deleteAllUsers() {
        return userService.deleteAllUsers();
    }
}
